package com.ebupt.dbmodule

import androidx.paging.PagingSource
import com.ebupt.common.base.BaseApplication
import com.ebupt.service.AppUserInfo
import com.ebupt.service.UserDaoHelper
import java.lang.Exception

class UserDataSource :PagingSource<Int,AppUserInfo>(){


    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AppUserInfo> {
            val currentLoadingPageKey = params.key ?: 1
            var userList =  UserDaoHelper.queryUserNomal(BaseApplication.context!!)
            val prevKey = if (currentLoadingPageKey == 1) null else currentLoadingPageKey - 1
            return LoadResult.Page(data = userList,prevKey = prevKey,nextKey = currentLoadingPageKey.plus(1))
    }
}